//
//  TopShowView.swift
//  FloatClock
//
//  Created by runbey_dev_ios on 2023/6/21.
//

import Foundation
import SnapKit

class TopShowView: UIView {
    
    lazy var title : UILabel = {
        let label = UILabel()
        label.text = "时钟"
        label.textColor = UIColor.colorWithHexString("#5F98FC");
        label.font = UIFont.systemFont(ofSize: 15)
        return label
    }()

    lazy var showLabel: UILabel = {
        let label = UILabel()
        label.textAlignment = .center
        label.textColor = UIColor.black;
        label.font = UIFont.systemFont(ofSize: 45)
        label.adjustsFontSizeToFitWidth = true
        label.baselineAdjustment = .alignCenters
        return label
    }()
    
    lazy var fpsLabel : FPSLabel = {
        let label = FPSLabel()
        label.isHidden = true
        label.textAlignment = .center
        label.textColor = UIColor.black;
        label.font = UIFont.systemFont(ofSize: 30)
        return label
    }()
    
    lazy var cpuLabel : CPULabel = {
        let label = CPULabel()
        label.isHidden = true
        label.textAlignment = .center
        label.textColor = UIColor.black;
        label.font = UIFont.systemFont(ofSize: 30)
        return label
    }()
    
    var showStyle : Int = 0 {
        didSet {
            if showStyle == 0 {
                title.text = "时钟"
                showLabel.isHidden = false;
                cpuLabel.isHidden = true;
                fpsLabel.isHidden = true;
            } else if showStyle == 1 {
                title.text = "CPU"
                showLabel.isHidden = true;
                cpuLabel.isHidden = false;
                fpsLabel.isHidden = true;
            } else{
                title.text = "FPS"
                showLabel.isHidden = true;
                cpuLabel.isHidden = true;
                fpsLabel.isHidden = false;
            }
        }
    }
        
    var isShowMilsecond: Bool = false {
        didSet {
            if isShowMilsecond {
                showLabel.snp.remakeConstraints { (make) in
                    make.centerX.equalToSuperview()
                    make.width.equalToSuperview().multipliedBy(293.0/353.0)
                    make.centerY.equalToSuperview().offset(-4)
                    make.height.equalTo(showLabel.snp.width).multipliedBy(62.0/293.0)
                }
            } else {
                showLabel.snp.remakeConstraints { (make) in
                    make.centerX.equalToSuperview()
                    make.width.equalToSuperview().multipliedBy(195.0/353.0)
                    make.centerY.equalToSuperview().offset(-4)
                    make.height.equalTo(showLabel.snp.width).multipliedBy(62.0/195.0)
                }
            }
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI() {
        
        addSubview(title)
        title.snp.makeConstraints { (make) in
            make.top.equalTo(20)
            make.centerX.equalToSuperview()
        }
        
        addSubview(fpsLabel)
        fpsLabel.snp.makeConstraints { (make) in
            make.left.equalTo(30)
            make.right.equalTo(-30)
            make.centerY.equalToSuperview()
        }
        
        addSubview(cpuLabel)
        cpuLabel.snp.makeConstraints { (make) in
            make.left.equalTo(30)
            make.right.equalTo(-30)
            make.centerY.equalToSuperview()
        }
        
        addSubview(showLabel)
        showLabel.snp.makeConstraints { (make) in
            make.left.equalTo(30)
            make.right.equalTo(-30)
            make.centerY.equalToSuperview()
        }
    }
    
}
